import Dep from "./dep";

let id = 0;
class Watcher { // 不同组件有不同的watcher
    constructor(vm, fn, options) { // 示例和渲染方法
        this.id = id++;
        this.renderWatcher = options;
        this.getter = fn;
        this.deps = []
        this.depsId = new Set()
        this.get();
    }
    get() {
        Dep.target = this;
        this.getter();
        Dep.target = null;
    }
    update() {
        console.log("1")
        this.get()
    }
    addDep(dep) {
        let id = dep.id;
        if (!this.depsId.has(id)){
            this.depsId.add(id);
            this.deps.push(dep);
            dep.addSub(this)
        }
    }
}
// 1个属性，对应n个watcher，多对多

export default Watcher;